package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.Car;
import cn.wolfcode.crm.page.PageResult;
import cn.wolfcode.crm.query.CarQueryObject;
import cn.wolfcode.crm.service.ICarService;
import cn.wolfcode.crm.util.JsonResult;
import cn.wolfcode.crm.util.PermissionName;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("car")
public class CarController {
    @Autowired
    private ICarService carService;

    @RequestMapping("")
    @RequiresPermissions(":index")
    @PermissionName("车辆列表")
    public String index() {
        //只负责跳转到car.jsp页面即可
        return "car";
    }

    @RequestMapping("list")
    @RequiresPermissions("car:list")
    @PermissionName("车辆数据")
    @ResponseBody
    public PageResult list(CarQueryObject  qo) {
        PageResult result = carService.query(qo);
        return result;
    }


    @RequestMapping("edit")
    @RequiresPermissions("car:edit")
    @PermissionName("车辆编辑")
    @ResponseBody
    public JsonResult edit(Car car) {
        JsonResult result = new JsonResult();
        try{
            carService.updateByPrimaryKey(car);
            result.setMessage("编辑成功");
        }catch (Exception e){
            e.printStackTrace();
            result.mark("编辑失败");
        }
        return result;
    }
    
}